package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.DailyCarriageQueryDto;
import com.leo.train.business.entity.DailyCarriage;
import com.leo.train.business.service.DailyCarriageService;
import com.leo.train.business.vo.DailyCarriageQueryVo;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/daily-carriage")
public class DailyCarriageAdminController {
    @Autowired
    private DailyCarriageService dailyCarriageService;
    /**
     * 新增
     * @param dailyCarriage
     */
    @PostMapping("/add")
    public CommonResp add(@Valid @RequestBody DailyCarriage dailyCarriage) {
        dailyCarriageService.save(dailyCarriage);
        return new CommonResp<>();
    }

    /**
     * 修改
     * @param dailyCarriage
     */
    @PostMapping("/update")
    public CommonResp update(@Valid @RequestBody DailyCarriage dailyCarriage) {
        dailyCarriageService.save(dailyCarriage);
        return new CommonResp<>();
    }

    /**
     * 删除
     * @param map
     */
    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Map<String,Long> map) {
        Long id = map.get("id");
        dailyCarriageService.deleteById(id);
        return new CommonResp<>();
    }

    /**
     * 查询车厢列表
     * @param dailyCarriageQueryDto
     */
    @GetMapping("/list")
    public CommonResp<PageResult<DailyCarriageQueryVo>> list(DailyCarriageQueryDto dailyCarriageQueryDto) {
        PageResult<DailyCarriageQueryVo> list = dailyCarriageService.list(dailyCarriageQueryDto);
        return new CommonResp<>(list);
    }

    /**
     * 查询车厢详情
     * @param id
     */
    @GetMapping("/detail")
    public CommonResp<DailyCarriageQueryVo> deatail(@RequestParam Long id) {
        DailyCarriageQueryVo detail = dailyCarriageService.detail(id);
        return new CommonResp<>(detail);
    }
}
